<?php
namespace app\api\service;
use think\Controller;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/26 0026
 * Time: 15:40
 */

class Member extends Controller {

    /**
     * 获取用户中心首页数据
     * @param $param
     * @return mixed
     */
    public static function get_member_index_data($param) {
        try {
            // 用户数据
            $member  = model('Member')->get(['id' => $param['member_id']]);

            //dump($member->memberRoleInfo);
            // 订单数据
            $order_model = model('order');
            $dfk = $order_model->where(['member_id' => $param['member_id'], 'status' => 1])->count();
            $ltsyjd = $order_model->where(['member_id' => $param['member_id'], 'status' => 3])->count();
            $yfh = $order_model->where(['member_id' => $param['member_id'], 'status' => 5])->count();
            $dpj = $order_model->where(['member_id' => $param['member_id'], 'status' => 6, 'comment_status' => 0, 'after_sale_status' => ['in', '0, 2']])->count();


            // 返回数据
            $data['nickname'] = $member->memberRoleInfo->nickname; // 昵称
            $data['headimgurl'] = $member->memberRoleInfo->headimgurl ? get_img_url($member->memberRoleInfo->headimgurl) : '';  // 头像
            $data['money'] = $member->money;  // 余额
            $data['integral'] = $member->integral;  // 积分
            $data['clothes_money'] = $member->clothes_money;  // 衣币
            $data['dfk'] = $dfk; // 待付款
            $data['ltsyjd'] = $ltsyjd; // 量体师已接单
            $data['yfh'] = $yfh; // 已发货
            $data['dpj'] = $dpj; // 待评价
            return api_return(200, $data);
        } catch (\Exception $e) {
            return api_return(0, [], $e->getMessage());
        }
    }
}